'use strict';
const Service = require('egg').Service;
class HomeService extends Service {
  async getRolpic() {
    // 假如 我们拿到用户 id 从数据库获取用户详细信息
    const rolpic = await this.app.mysql.select('rollingpic', {
      where: { ava: 1 },
    });
    return rolpic;
  }

  async getThemeinfo() {
    const themeinfo = await this.app.mysql.select('theme', {
      where: { ava: 1 },
      limit: 2,
    });
    return themeinfo;
  }

  async getClassinfo() {
    const classinfo = await this.app.mysql.select('class', {
      where: { ava: 1 },
      limit: 2,
      columns: [ 'id', 'classname', 'brief', 'learningnum', 'startpic', 'price', 'class_id' ],
    });
    return classinfo;
  }

  async getPicture(uid) {
    const result = await this.ctx.curl(`http://photoserver/uid=${uid}`, { dataType: 'json' });
    return result.data;
  }
}
module.exports = HomeService;
